package admin.forms;

import java.net.URL;
import java.util.Map;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import com.google.appengine.api.blobstore.BlobInfo;
import com.google.appengine.api.blobstore.BlobInfoFactory;
import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;

import entities.MetaHeader;
import entities.SiteConfig;

public class MetaHeaderForm {
	private static BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
	
	public static TreeMap checkValidSite(HttpServletRequest request, MetaHeader metaHeader) {
		TreeMap form = new TreeMap();
		TreeMap check = new TreeMap();
		
		String title = (String) request.getParameter("title");
		String keywords = (String) request.getParameter("keywords");
		String description = (String) request.getParameter("description");
		String ogSiteName = (String) request.getParameter("ogSiteName");
		String ogTitle = (String) request.getParameter("ogTitle");
		String ogUrl = (String) request.getParameter("ogUrl");
		String ogImage = (String) request.getParameter("ogImage");
		String ogDescription = (String) request.getParameter("ogDescription");
		
		if (title == null || title.isEmpty()) {
			check.put("title", "Title is not empty!");
			metaHeader.setTitle("");
		} else {
			metaHeader.setTitle(title);
		}
		
		if (keywords == null || keywords.isEmpty()) {
			check.put("keywords", "Keywords is not empty!");
			metaHeader.setKeywords("");
		} else {
			metaHeader.setKeywords(keywords);
		}
		
		
		
		form.put("checkValid", check);
		form.put("metaHeader", metaHeader);
		
		return form;
	}
	
	public static TreeMap checkValidEmail(HttpServletRequest request, SiteConfig config) {
		TreeMap form = new TreeMap();
		TreeMap check = new TreeMap();
		
		form.put("checkValid", check);
		form.put("config", config);
		
		return form;
	}
	
	private static boolean checkImage(String name) {
		boolean valid = false;
		
		Pattern pattern = Pattern.compile("([^\\s]+(\\.(?i)(jpg|png|gif|bmp))$)");
		Matcher matcher = pattern.matcher(name);
		
		return matcher.matches();
	}
}
